package TableHelpers;

import SQLAPI.SQL;
import SQLAPI.TransactionDetail;
import java.util.ArrayList;

/**
 *This class generates an HTML table containing TransactionDetail information.
 * @author Scott Catsirelis - 602705
 */
public class WebUserTransDetails {

    private final SQL sql = new SQL();
    
    public WebUserTransDetails() {
    }
    
    /**
     * Returns a String that contains an HTML table with Transaction Detail
     * information.
     * @param transid - int - Transaction ID of the transaction to fetch details for.
     * @return - String - A built HTML table containing transaction detail information.
     */
    public String createTable(int transid)
    {
        String table="<thead><tr>";
        table += "<th>Transaction ID</th>";
        table += "<th>Object Name</th>";
        table += "<th>Attribute Name</th>";
        table += "<th>Previous Value</th>";
        table += "<th>New Value</th>";
        table += "</tr></thead>";
        table += "<tbody>";
        ArrayList<TransactionDetail> list = sql.getTransactionDetails(transid);
        for(int i=0;i<list.size();i++)
        {
            TransactionDetail t = list.get(i);
            table += "<tr>";
            table += "<td>"+t.getTransid()+"</td>";
            table += "<td>"+t.getObjName()+"</td>";
            table += "<td>"+t.getAttribName()+"</td>";
            table += "<td>"+t.getPrev()+"</td>";
            table += "<td>"+t.getNewValue()+"</td>";
            table += "</tr>";
        }
        table+="</tbody>";
        
        return table;
    }
}
